package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.RateTypeDao;
import com.hy.erp.inventory.dao.interfaces.IRateTypeDao;
import com.hy.erp.inventory.pojo.RateType;
import com.hy.erp.inventory.pojo.interfaces.IRateType;
import com.hy.erp.inventory.service.interfaces.IRateTypeService;

/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-11-18；时间：下午12:59:27</li>
 * <li>类型名称：RateTypeService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@ Name ( "rateTypeService" )
@ Scope ( ScopeType.SESSION )
@ Stateless
public class RateTypeService extends AbstractBusinessService < IRateType > implements IRateTypeService
{

	@ Override
	public boolean addRateType (
									IRateType rateType )
	{




		if ( null == rateType)
		{
			return true ;
		}
		
		else
		{

			IRateTypeDao rateTypeDao =
			                       ( IRateTypeDao ) this
			                                          .getDao ( IRateType.class ) ;
			
		
			return rateTypeDao
			                .persist ( rateType ) ;
		}
		
	
	
	
	
	}

	@ Override
	public boolean modifyRateType (
									IRateType rateType )
	{





		if ( ( null == rateType )
		     || ( null == rateType
		                                .getIdentifier ( ) )
		     || ( rateType
		                        .getIdentifier ( )
		                        .trim ( )
		                        .length ( ) == 0 ) )
		{
			return true ;
		}
		else
		{
			IRateTypeDao rateTypeDao =
                ( IRateTypeDao ) this
                                   .getDao ( IRateType.class ) ;


				
			if ( null == rateType )
			{
				throw new ArchitectureFoundationException  (
				                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			
			
			return ( rateTypeDao
			                  .merge ( rateType ) != null ) ;
		}
	
	
	
	
	
	
	}

	@ Override
	public Integer removeRateType (
									String [ ] rateTypeIds )
	{



		if ( ( null == rateTypeIds )
			     || ( rateTypeIds.length == 0 ) )
		{
			return new Integer (
			                     0 ) ;
		}
		else
		{
			IRateTypeDao rateTypeDao =
                ( IRateTypeDao ) this
                                   .getDao ( IRateType.class ) ;


			return rateTypeDao
			                .remove ( rateTypeIds ) ;
		}
		
	
	
	
	
	}

	@ Override
	public String [ ] addRateType (
									Object [ ] objects )
	{
		IRateTypeDao rateTypeDao =
            ( IRateTypeDao ) this
                               .getDao ( IRateType.class ) ;
		RateType[] types=new RateType[objects.length];
		for ( int i =
						0 ; i < objects.length ; i ++ )
		{
			RateType type=( RateType ) objects[i];
			types[i]=type;
		}
		return rateTypeDao.persist ( types ) ;
	}

	@ Override
	public List < IRateType > getAllRateType ( )
	{
		IRateTypeDao rateTypeDao =
            ( IRateTypeDao ) this
                               .getDao ( IRateType.class ) ;
		return rateTypeDao.find ( ) ;
	}

	@ Override
	public String [ ] modifyRateType (
										Object [ ] objects )
	{
		if (  null == objects ) 
		{
			return null;
		}
		else
		{
			IRateTypeDao rateTypeDao =
	            ( IRateTypeDao ) this
	                               .getDao ( IRateType.class ) ;
			RateType[] types=new RateType[objects.length];
            for(int i=0;i<objects.length;i++)
            {
            	RateType type=( RateType ) objects[i];
            	types[i]=type;
            }
			
			return rateTypeDao.merge ( types );
		}
	}

}
